package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

import java.util.ArrayList;

public class OtherStudentDao extends BaseStudentDao{
    //private static Student[] stus = new Student[5];
   private static ArrayList<Student> stus = new ArrayList<>();
    static {
        Student stu1 = new Student("heima001","张三","21","1995-02-04");
        Student stu2 = new Student("heima002","李四","20","1994-12-07");
        stus.add(stu1);
        stus.add(stu2);
    }
    //添加学生方法
    public  boolean addStudent(Student stu) {
      stus.add(stu);
      return true;
    }
    //查看学生方法
    public  Student[] findAllStudent(){
        Student[] student = new Student[stus.size()];
        for (int i = 0; i <student.length ; i++) {
            student[i] = stus.get(i);

        }
        return  student;
    }
    public  void deleteStudentById(String delId) {
        //查找id在容器中的索引位置
        int index = getIndex(delId);
        stus.remove(index);
    }
    public  int getIndex(String id){
        int index = -1;
        for (int i = 0; i <stus.size() ; i++) {
            Student stu =stus.get(i);
            if (stu !=null && stu.getId().equals(id)){
                index = i;
                break;
            }
        }
        return index;
    }
    public void updateStudent(String updateId, Student newStu){
        int index = getIndex(updateId);
        stus.set(index,newStu);
    }
}